package com.management.department.teacherinfosystem.Repository;
import com.management.department.teacherinfosystem.Entity.Attachment;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface AttachmentRepository extends JpaRepository<Attachment, Long>{
    List<Attachment> findByRelatedTypeAndRelatedId(String relatedType, Long relatedId);
    
    @Modifying
    @Transactional
    @Query("DELETE FROM Attachment a WHERE a.relatedId = :relatedId AND a.relatedType = :relatedType")
    void deleteByRelatedIdAndRelatedType(@Param("relatedId") Long relatedId, @Param("relatedType") String relatedType);
}
